home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / macgetaddr / macgetaddr.c next >
C/C++ Source or Header  |  1995-05-03  |  922b  |  47 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/stream.h>
  4. #include <sys/stropts.h>
  5. #include <sys/macstat.h>
  6.  
  7. main(argc, argv)
  8.     int    argc;
  9.     char    *argv[];
  10. {
  11.     struct strioctl    strioc;
  12.     u_char        ether_addr[6];
  13.     int        s;
  14.  
  15.     if (argc != 2) {
  16.         fprintf(stderr, "usage: %s deviceFile\n", argv[0]);
  17.         exit (1);
  18.     }
  19.  
  20.     ether_addr[0] = 0;
  21.     ether_addr[1] = 0;
  22.     ether_addr[2] = 0;
  23.     ether_addr[3] = 0;
  24.     ether_addr[4] = 0;
  25.     ether_addr[5] = 0;
  26.  
  27.     if ((s = open(argv[1], 0)) < 0) {
  28.         perror(argv[1]);
  29.         exit(1);
  30.     }
  31.     strioc.ic_cmd = MACIOC_GETADDR;
  32.     strioc.ic_timout = -1;
  33.     strioc.ic_len = sizeof(ether_addr);
  34.     strioc.ic_dp = (caddr_t) ether_addr;
  35.     if (ioctl(s, I_STR, (char *) &strioc) < 0) {
  36.         perror("I_STR: MACIOC_GETADDR");
  37.         exit(1);
  38.     }
  39.  
  40.     printf("%s is using address %02x:%02x:%02x:%02x:%02x:%02x\n",
  41.             argv[1],
  42.             ether_addr[0], ether_addr[1], ether_addr[2],
  43.             ether_addr[3], ether_addr[4], ether_addr[5]);
  44.         
  45.     exit(0);
  46. }
  47.